package demo.condition.dao;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import demo.condition.connection.MyConnection;
import demo.condition.connection.MyConnectionCondition;


@Configuration
public class MyDao {
    //private String connection="success";
    private MyConnection myConnection;    
    @Autowired
    @Qualifier("d1")
    private Date date;

    @Bean(name="myConnection")
    public MyConnection myConnection() {
        return new MyConnection();
    }    
    @Bean(name="dao")
    @Conditional(MyConnectionCondition.class)
    public MyDao getBean() {
        MyDao dao=new MyDao();
        dao.setMyConnection(myConnection);
        return dao;
    }

    public void insert() {
        myConnection().getConnection();
        System.out.println("可以向数据库进行插入。" + date);
    }

    public MyConnection getMyConnection() {
        return myConnection;
    }

    public void setMyConnection(MyConnection myConnection) {
        this.myConnection = myConnection;
    }
    @Bean
    public Date d1() {
        return new Date() ;
    }

    @Bean
    public Date d2() {
        return new Date() ;
    }

}
